﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace NeurOthello.Logic
{
    public class HumanPlayer : Player
    {
        Position move = new Position(-1, -1);
        bool isWaiting = false;
        public PlayerSettings Set { get; set; }
        #region Player Members

        public bool IsCpu { get { return false; } }

        public HumanPlayer()
        {
            this.Set = new PlayerSettings();
            Set.IsCpu = false;
        }

        public Position MakeMove(int playerId)
        {
            return getMove();
        }

        public Position MakeTrainingMove(int playerId)
        {
            return getMove();
        }

        public void TrainPlayer(double[] result) { }

        #endregion

        public void enterMove(int x, int y)
        {            
            if (isWaiting)
            {
                System.Threading.Monitor.Enter(move);
                move.X = x;
                move.Y = y;
                System.Threading.Monitor.PulseAll(move);
                System.Threading.Monitor.Exit(move);
                
            }
        }

        public Position getMove()
        {
            try
            {
                System.Threading.Monitor.Enter(move);
                move.X = -1;
                move.Y = -1;
                isWaiting = true;
                System.Threading.Monitor.Wait(move);
                isWaiting = false;
                return move;
            }
            finally
            {
                System.Threading.Monitor.Exit(move);
            }
        }

        
        public void SetGame(Othello game) {}
 
    }
}
